﻿namespace Searches
{
    public class BubbleSort : ISortingAlgorythm
    {
        public void Sort(int[] array)
        {
            int numberOfPairs = array.Length;

            bool swappedElements = true;
            while (swappedElements)
            {
                --numberOfPairs;
                swappedElements = false;
                for (int i = 0; i < numberOfPairs; i++)
                {
                    if(array[i]>array[i+1])
                    {
                        int temp = array[i];
                        array[i] = array[i + 1];
                        array[i + 1] = temp;

                        swappedElements = true;
                    }
                }
            }
        }
    }
}